import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:lib_uikit/widgets/gt_pop_menu_widget_v3.dart';

class GTPopMenuV3 extends StatelessWidget {
  //目标控件
  final Widget child;
  final List<GTPopMenuModalV3> list;
  final double width;
  final ValueChanged<GTPopMenuModalV3>? onItemClicked;

  const GTPopMenuV3({
    super.key,
    required this.child,
    required this.list,
    required this.width,
    this.onItemClicked,
  });

  @override
  Widget build(BuildContext context) {
    return Builder(builder: (context) {
      return GestureDetector(
        onTap: () {
          SmartDialog.showAttach(
            maskColor: Colors.transparent,
            targetContext: context,
            alignment: Alignment.bottomCenter,
            animationType: SmartAnimationType.scale,
            builder: (_) {
              return GTPopMenuWidgetV3(
                list: list,
                width: width,
                onItemClicked: onItemClicked,
              );
            },
          );
        },
        child: child,
      );
    });
  }

  static void showAttach(
      BuildContext ctx, List<GTPopMenuModalV3> list, double? width, ValueChanged<GTPopMenuModalV3>? onItemClicked,
      {Offset? offset}) {
    SmartDialog.showAttach(
      maskColor: Colors.transparent,
      targetContext: ctx,
      alignment: Alignment.bottomCenter,
      animationType: SmartAnimationType.scale,
      builder: (_) {
        return Transform.translate(
          offset: offset ?? const Offset(0, 0), // 偏移量
          child: GTPopMenuWidgetV3(
            list: list,
            width: width,
            onItemClicked: onItemClicked,
          ),
        );
      },
    );
  }
}
